package com.google.gwt.homepage.smile.client.view;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.logical.shared.HasSelectionHandlers;
import com.google.gwt.event.logical.shared.SelectionEvent;



import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DeckPanel;
import com.google.gwt.user.client.ui.DecoratedTabPanel;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.HTMLTable;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.homepage.smile.client.presenter.EnneagramFeaturesPresenter;
import com.google.gwt.homepage.smile.shared.EnneagramTestResultBean;
import com.google.gwt.i18n.client.Constants;
import com.google.gwt.i18n.client.LocaleInfo;

import com.google.gwt.homepage.smile.shared.EnneagramQuestions;

import java.util.ArrayList;
import java.util.List;

public class EnneagramFeaturesView extends Composite implements EnneagramFeaturesPresenter.Display {
  
	
	
	/**
	   * The constants used in this Widget.
	   */
	  
	  public static interface CwConstants extends Constants {
		String enneagramFeaturesTitle();
		String enneagramFeaturesDesc();
		String[] enneagramFeaturesTabs();
	  }
	
	  private CwConstants constants;
	  
	  
	//private final Button addButton;
  //private final Button deleteButton;
  //private FlexTable contactsTable;
  private final FlexTable contentTable;
  
  
  
  private DecoratedTabPanel tabPanel =null;
  
  
  private HTML sourceWidget[] = new HTML[9];
  /*
  private HTML type1info = new HTML();
  private HTML type2info = new HTML();
  private HTML type3info = new HTML();
  private HTML type4info = new HTML();
  private HTML type5info = new HTML();
  private HTML type6info = new HTML();
  private HTML type7info = new HTML();
  private HTML type8info = new HTML();
  private HTML type9info = new HTML();
  */

  
  
  /**
   * The default style name.
   */
  private static final String DEFAULT_STYLE_NAME = "sc-ContentWidget";
	
  
  public EnneagramFeaturesView(CwConstants constants) {
	  
	  this.constants=constants;
	  
	  
    //DecoratorPanel contentTableDecorator = new DecoratorPanel();
	  VerticalPanel contentTableDecorator = new VerticalPanel();
    initWidget(contentTableDecorator);
    contentTableDecorator.setWidth("100%");
    
    //contentTableDecorator.setWidth("18em");

    contentTable = new FlexTable();
    contentTable.setWidth("100%");
    contentTable.getCellFormatter().addStyleName(0, 0, "contacts-ListContainer");
    contentTable.getCellFormatter().setWidth(0, 0, "100%");
    contentTable.getFlexCellFormatter().setVerticalAlignment(0, 0, DockPanel.ALIGN_TOP);
    
    
    //
    // Create submenu, description
    VerticalPanel widgetVpanel = new VerticalPanel();
    contentTable.setWidget(0, 0, widgetVpanel);

    // Add the name
    HTML nameWidget = new HTML(constants.enneagramFeaturesTitle());
    nameWidget.setStyleName(DEFAULT_STYLE_NAME + "-name");
    widgetVpanel.add(nameWidget);

    // Add the description
    //HTML descWidget = new HTML("You can test Enneagram( total 180 question.  It takes about 15minute.)");
    HTML descWidget = new HTML(constants.enneagramFeaturesDesc());
    descWidget.setStyleName(DEFAULT_STYLE_NAME + "-description");
    widgetVpanel.add(descWidget);
    

 // Create a tab panel
    tabPanel = new DecoratedTabPanel();
    tabPanel.setWidth("400px");
    tabPanel.setAnimationEnabled(true);

    
   
    
    String[] tabTitles = constants.enneagramFeaturesTabs();
    /*
     * // 1유형 tab
    //HTML homeText = new HTML(constants.cwTabPanelTab0());
    HTML oneText = new HTML("<h1> 이상적-규율있는-완벽주의의-편협한 사람</h1><h2>삶의 태도</h2><h3>이들은 타인들을 공평하게 다루고 싶어하고 이상을 위해 투쟁하고 싶어하며 세상을 개선하고 싶어하고 모든 것을 통제하여 실수가 없도록 만들고 싶어하고 비난을 초월하고 싶어하고 그들의 위치를 정당화하고 싶어하고 완전히 죄책감없이 살고 싶어하고 그들의 이상에 맞추어 살지 않는 사람들을 비난하고 싶어한다.</h3>");
    tabPanel.add(oneText, tabTitles[0]);
    
    // 2유형
    //VerticalPanel vPanel = new VerticalPanel();
    //vPanel.add(new Image(Smile.images.gwtLogo()));
    HTML twoText = new HTML("2유형에 대한 설명입니다.");
    tabPanel.add(twoText, tabTitles[1]);

   // 3유형
    HTML threeText = new HTML("3유형에 대한 설명입니다.");
    tabPanel.add(threeText, tabTitles[2]);
    
   // 4유형
    //VerticalPanel vPanel = new VerticalPanel();
    //vPanel.add(new Image(Smile.images.gwtLogo()));
    HTML fourText = new HTML("<h1>창조적-개인적-내성적-우울한<h1><h2>삶의 태도<h2><h3>4유형의 사람들은 자신들을 표현하고싶어하고, 자신들을 남들과 연결시켜줄수 있는 아름다운 무엇인가를 만들어내고 싶어하고, 자신들이 진정되거나 자신들의 감정을 보호하기 위해 사람들로부터 떨어져 있기도 하고, 무엇보다 자신들의 감정적인 문제를 해결하려 하고, 자신들이 실제 세상에서 얻지 못한 것들을 환상 속에서 얻으려고 한다.</h3>");
    tabPanel.add(fourText, tabTitles[3]);
    
 // 5유형
    //VerticalPanel vPanel = new VerticalPanel();
    //vPanel.add(new Image(Smile.images.gwtLogo()));
    HTML fiveText = new HTML("5유형에 대한 설명입니다.");
    tabPanel.add(fiveText, tabTitles[4]);
    
 //6유형
    //VerticalPanel vPanel = new VerticalPanel();
    //vPanel.add(new Image(Smile.images.gwtLogo()));
    HTML sixText = new HTML("6유형에 대한 설명입니다.");
    tabPanel.add(sixText, tabTitles[5]);
    
 //7유형
    //VerticalPanel vPanel = new VerticalPanel();
    //vPanel.add(new Image(Smile.images.gwtLogo()));
    HTML sevenText = new HTML("7유형에 대한 설명입니다.");
    tabPanel.add(sevenText, tabTitles[6]);
    
 //8유형
    //VerticalPanel vPanel = new VerticalPanel();
    //vPanel.add(new Image(Smile.images.gwtLogo()));
    HTML eightText = new HTML("8유형에 대한 설명입니다.");
    tabPanel.add(eightText, tabTitles[7]);
   
 // 9유형
    //VerticalPanel vPanel = new VerticalPanel();
    //vPanel.add(new Image(Smile.images.gwtLogo()));
    HTML nineText = new HTML("9유형에 대한 설명입니다.");
    tabPanel.add(nineText, tabTitles[8]);
    */
    
    
    
    for(int i=0; i<9; i++){
    	
    	sourceWidget[i]=new HTML();
    	
    	tabPanel.add(sourceWidget[i],tabTitles[i]);
    	
    	//tabPanel.getDeckPanel().add(sourceWidget[i]);
    	//tabPanel.getTabBar().addTab(tabTitles[i]);
    }
    /*
    tabPanel.add(type1info,tabTitles[0]);
    tabPanel.add(type2info,tabTitles[1]);
    tabPanel.add(type3info,tabTitles[2]);
    tabPanel.add(type4info,tabTitles[3]);
    tabPanel.add(type5info,tabTitles[4]);
    tabPanel.add(type6info,tabTitles[5]);
    tabPanel.add(type7info,tabTitles[6]);
    tabPanel.add(type8info,tabTitles[7]);
    tabPanel.add(type9info,tabTitles[8]);
    */
    
    
    
    //tabPanel.selectTab(3);
    
   
    contentTable.setWidget(1, 0, tabPanel);
    contentTableDecorator.add(contentTable);
   
  }
  /*
  public HasClickHandlers getAddButton() {
    return addButton;
  }
  
  public HasClickHandlers getDeleteButton() {
    return deleteButton;
  }
  
  public HasClickHandlers getList() {
    return contactsTable;
  }

  public void setData(List<String> data) {
    contactsTable.removeAllRows();
    
    for (int i = 0; i < data.size(); ++i) {
      contactsTable.setWidget(i, 0, new CheckBox());
      contactsTable.setText(i, 1, data.get(i));
    }
  }
  
  public int getClickedRow(ClickEvent event) {
    int selectedRow = -1;
    HTMLTable.Cell cell = contactsTable.getCellForEvent(event);
    
    if (cell != null) {
      // Suppress clicks if the user is actually selecting the 
      //  check box
      //
      if (cell.getCellIndex() > 0) {
        selectedRow = cell.getRowIndex();
      }
    }
    
    return selectedRow;
  }
  
  public List<Integer> getSelectedRows() {
    List<Integer> selectedRows = new ArrayList<Integer>();
    
    for (int i = 0; i < contactsTable.getRowCount(); ++i) {
      CheckBox checkBox = (CheckBox)contactsTable.getWidget(i, 0);
      if (checkBox.getValue()) {
        selectedRows.add(i);
      }
    }
    
    return selectedRows;
  }
  */
  
 
  
  public HasSelectionHandlers getTabPanel(){
	  return tabPanel;
  }

  public void setTypeInfo(int typeIndex, String content){
	  //System.out.println(typeIndex+"_"+content);

	  sourceWidget[typeIndex].setHTML(content);
	  
	  /*
	  if(typeIndex==0){
		  type1info.setHTML(content);
	  }else if(typeIndex==1){
		  type2info.setHTML(content);
	  }
	  System.out.println("!!!!!!!!!!!!!!!!!!"+type1info.toString());
	  System.out.println("??????????????????"+tabPanel.getWidget(typeIndex) );
	  */
  }
  
  public void selectTypeTap(int typeIndex){
	  tabPanel.selectTab(typeIndex);
  }
  
  public Widget asWidget() {
    return this;
  }
}
